﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;

using XJX.DBCore;

namespace XJX.DataLayer
{
    public sealed class Family : XJX.DBCore.DBObject
    {
        public Family(string newConnectionString) : base(newConnectionString) { }

        //修改家庭信息
        public bool modify_One_Family_Info
        (
            string UID,
            string Sname,
            string sex,
            string Fname,
            string mobile,
            out int ReturnValue
            )
        {
            int rowsAffected;

            SqlParameter[]
                parameters = {
								 new SqlParameter("@uid",SqlDbType.UniqueIdentifier),
								 new SqlParameter("@sname",SqlDbType.VarChar,8), 
								 new SqlParameter("@sex",SqlDbType.Char,2),
								 new SqlParameter("@fname",SqlDbType.VarChar,8),
								 new SqlParameter("@mobile",SqlDbType.VarChar,11 )
			};

            parameters[0].Value = new Guid(UID);
            parameters[1].Value = Sname;
            parameters[2].Value = sex;
            parameters[3].Value = Fname;
            parameters[4].Value = mobile;

            try
            {
                ReturnValue = RunProcedure("modify_One_Family_Info", parameters, out rowsAffected);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return (rowsAffected == 1);
        }

        //依据UID，获取家庭用户信息
        public DataSet Get_One_Family_Info_From_UID(string UID)
        {

            SqlParameter[]
                parameters = {
								 new SqlParameter("@UID", SqlDbType.UniqueIdentifier),
							 };

            parameters[0].Value = new Guid(UID);

            using (DataSet ds = RunProcedure("Get_One_Family_Info_From_UID", parameters, "OneFamilyInfo"))
            {
                return ds;
            }
        }

    }
}
